package cn.lysj.framework.api.controller;

import cn.lysj.framework.api.base.ApiContent;
import cn.lysj.framework.common.utils.web.ParamUtil;
import cn.lysj.framework.common.utils.web.Resp;
import cn.lysj.framework.foodv2.domain.Food;
import cn.lysj.framework.foodv2.domain.FoodType;
import cn.lysj.framework.foodv2.domain.StandardLevOne;
import cn.lysj.framework.foodv2.domain.StandardLevTwo;
import cn.lysj.framework.foodv2.vo.FoodTypeVo;
import cn.lysj.framework.foodv2.vo.FoodVo;
import cn.lysj.framework.foodv2.vo.StandVo;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @Author: ZhangWenJian
 * @Create: 2018/10/29--16:31
 * @Description:菜单模块
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(value = "ApiMenusController", tags = "菜单模块接口")
public class ApiMenusController extends ApiContent {
    //品类列表
    @GetMapping("/get_food_type")
    public Resp getFoodType(String storeId) {
        if (ParamUtil.isBlank(storeId)) {
            return new Resp(Resp.PARAM_ERROR, "获取失败,未识别到门户ID!");
        }
        List<FoodType> foodTypes = foodTypeRepository.findByStoreIdOrderByRankDesc(storeId);
        List<FoodTypeVo> foodTypeVos = new ArrayList<>();
        for (FoodType foodType : foodTypes) {
            FoodTypeVo foodTypeVo = new FoodTypeVo();
            foodTypeVo.setId(foodType.getId());
            foodTypeVo.setName(foodType.getName());
            List<FoodVo> foods = foodTypeAndFoodContactRepository.obtainFoodInFoodType(foodType.getId());
            for (FoodVo foodVo : foods) {
                foodVo.setStandVos(standardLevOneService.getStandVo(foodVo.getId()));
            }
            foodTypeVo.setFoodVos(foods);
            foodTypeVos.add(foodTypeVo);
        }
        return new Resp(foodTypeVos);
    }


}
